home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / ole2book.zip / CHAP07.ZIP / CHAP07 / COSCHMOO / COSCHMOO.H < prev    next >
C/C++ Source or Header  |  1993-04-14  |  7KB  |  232 lines

  1. /*
  2.  * COSCHMOO.H
  3.  * Component Schmoo Chapter 7
  4.  *
  5.  * Single include file that pulls in everything needed for other source
  6.  * files in the Schmoo application.
  7.  *
  8.  * Copyright (c)1993 Microsoft Corporation, All Rights Reserved
  9.  *
  10.  * Kraig Brockschmidt, Software Design Engineer
  11.  * Microsoft Systems Developer Relations
  12.  *
  13.  * Internet  :  kraigb@microsoft.com
  14.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  15.  */
  16.  
  17.  
  18. #ifndef _COSCHMOO_H_
  19. #define _COSCHMOO_H_
  20.  
  21. #include <windows.h>
  22. #include <memory.h>
  23. #include <ole2.h>
  24. #include <ole2ver.h>
  25. #include <bookguid.h>
  26. #include <ipoly6.h>
  27.  
  28. //These include files reference DLLs that don't have extern "C" already
  29. extern "C"
  30.     {
  31.     #include <commdlg.h>
  32.     }
  33.  
  34. #include <classlib.h>
  35. #include "resource.h"
  36.  
  37.  
  38.  
  39. //COSCHMOO.CPP:  Frame object that creates a main window
  40.  
  41. class __far CSchmooFrame : public CFrame
  42.     {
  43.     private:
  44.         HBITMAP         m_hBmpLines[5];     //Menu item bitmaps
  45.  
  46.         BOOL            m_fInitialized;     //CoInitialize work?
  47.  
  48.     protected:
  49.         //Overridable for creating a CClient for this frame
  50.         virtual LPCClient CreateCClient(void);
  51.  
  52.         //FRegisterAllClasses override unneccessary with Polyline DLL
  53.         virtual BOOL      FPreShowInit(void);
  54.         virtual UINT      CreateGizmos(void);
  55.  
  56.         virtual LRESULT   OnCommand(HWND, WPARAM, LPARAM);
  57.         virtual void      OnDocumentDataChange(LPCDocument);
  58.         virtual void      OnDocumentActivate(LPCDocument);
  59.  
  60.         //New for this class
  61.         virtual void      CreateLineMenu(void);
  62.  
  63.     public:
  64.         CSchmooFrame(HINSTANCE, HINSTANCE, LPSTR, int);
  65.         virtual ~CSchmooFrame(void);
  66.  
  67.         //Overrides
  68.         virtual BOOL      FInit(LPFRAMEINIT);
  69.         virtual void      UpdateMenus(HMENU, UINT);
  70.         virtual void      UpdateGizmos(void);
  71.  
  72.         //New for this class
  73.         virtual void      CheckLineSelection(UINT);
  74.     };
  75.  
  76.  
  77. typedef CSchmooFrame FAR * LPCSchmooFrame;
  78.  
  79.  
  80.  
  81.  
  82.  
  83. //CLIENT.CPP
  84.  
  85. /*
  86.  * The only reason we have a derived class here is to override
  87.  * CreateCDocument so we can create our own type as well as
  88.  * overriding NewDocument to perform one other piece of work once the
  89.  * document's been created.
  90.  */
  91.  
  92. class __far CSchmooClient : public CClient
  93.     {
  94.     protected:
  95.         //Overridable for creating a new CDocument
  96.         virtual LPCDocument CreateCDocument();
  97.  
  98.     public:
  99.         CSchmooClient(HINSTANCE);
  100.         virtual ~CSchmooClient(void);
  101.  
  102.         virtual LPCDocument NewDocument(BOOL, LPCDocumentAdviseSink);
  103.     };
  104.  
  105.  
  106. typedef CSchmooClient FAR * LPCSchmooClient;
  107.  
  108.  
  109.  
  110.  
  111. //DOCUMENT.CPP
  112.  
  113. class __far CPolylineAdviseSink : public IPolylineAdviseSink6
  114.     {
  115.     private:
  116.         LPVOID              m_pv;        //Customizable structure
  117.         ULONG               m_cRef;
  118.         LPUNKNOWN           m_punkOuter; //Unknown for delegation
  119.  
  120.     public:
  121.         CPolylineAdviseSink(LPVOID, LPUNKNOWN);
  122.         ~CPolylineAdviseSink(void);
  123.  
  124.         //IUnknown members
  125.         STDMETHODIMP         QueryInterface(REFIID, LPVOID FAR *);
  126.         STDMETHODIMP_(ULONG) AddRef(void);
  127.         STDMETHODIMP_(ULONG) Release(void);
  128.  
  129.         //Advise members.
  130.         STDMETHODIMP_(void) OnPointChange(void);
  131.         STDMETHODIMP_(void) OnSizeChange(void);
  132.         STDMETHODIMP_(void) OnColorChange(void);
  133.         STDMETHODIMP_(void) OnLineStyleChange(void);
  134.     };
  135.  
  136. typedef CPolylineAdviseSink FAR * LPCPolylineAdviseSink;
  137.  
  138.  
  139. /*
  140.  * The generic advisory interface.  This object controls it's own
  141.  * lifetime and the document becomes a user of the object with
  142.  * the last reference count.
  143.  */
  144.  
  145. class __far CImpIAdviseSink : public IAdviseSink
  146.     {
  147.     protected:
  148.         ULONG               m_cRef;      //Interface reference count.
  149.         LPVOID              m_pObj;      //Back pointer to the document
  150.         LPUNKNOWN           m_punkOuter; //Unknown for delegation
  151.  
  152.     public:
  153.         CImpIAdviseSink(LPVOID, LPUNKNOWN);
  154.         ~CImpIAdviseSink(void);
  155.  
  156.         STDMETHODIMP QueryInterface(REFIID, LPVOID FAR *);
  157.         STDMETHODIMP_(ULONG) AddRef(void);
  158.         STDMETHODIMP_(ULONG) Release(void);
  159.  
  160.         STDMETHODIMP_(void)  OnDataChange(LPFORMATETC, LPSTGMEDIUM);
  161.         STDMETHODIMP_(void)  OnViewChange(DWORD, LONG);
  162.         STDMETHODIMP_(void)  OnRename(LPMONIKER);
  163.         STDMETHODIMP_(void)  OnSave(void);
  164.         STDMETHODIMP_(void)  OnClose(void);
  165.     };
  166.  
  167.  
  168.  
  169. //Constant ID for the window polyline that lives in a document window
  170. #define ID_POLYLINE         10
  171.  
  172.  
  173. class __far CSchmooDoc : public CDocument, public IUnknown
  174.     {
  175.     friend class CPolylineAdviseSink;
  176.     friend class CImpIAdviseSink;
  177.  
  178.     protected:
  179.         UINT                    m_uPrevSize;        //Last WM_SIZE wParam
  180.  
  181.         //Interface we use on the Polyline Object
  182.         LPPOLYLINE              m_pPL;
  183.         LPPERSISTSTORAGE        m_pIPersistStorage;
  184.  
  185.         //Interfaces we implement
  186.         LPPOLYLINEADVISESINK    m_pPLAdv;       //Polyline
  187.         LPADVISESINK            m_pIAdviseSink; //Standard for OnDataChange
  188.  
  189.         DWORD                   m_dwConn;       //Advisory connection
  190.         ULONG                   m_cRef;         //Document ref count
  191.  
  192.     protected:
  193.         virtual BOOL    FMessageHook(HWND, UINT, WPARAM, LPARAM, LRESULT FAR *);
  194.  
  195.     public:
  196.         CSchmooDoc(HINSTANCE);
  197.         virtual ~CSchmooDoc(void);
  198.  
  199.         //Since we implement multiple interfaces we need a controlling unknown
  200.         STDMETHODIMP         QueryInterface(REFIID, LPVOID FAR *);
  201.         STDMETHODIMP_(ULONG) AddRef(void);
  202.         STDMETHODIMP_(ULONG) Release(void);
  203.  
  204.         virtual BOOL     FInit(LPDOCUMENTINIT);
  205.         virtual void     Clear();
  206.  
  207.         virtual UINT     ULoad(BOOL, LPSTR);
  208.         virtual UINT     USave(UINT, LPSTR);
  209.  
  210.         virtual void     Undo(void);
  211.         virtual BOOL     FClip(HWND, BOOL);
  212.         virtual BOOL     FQueryPaste(void);
  213.         virtual BOOL     FPaste(HWND);
  214.  
  215.         virtual COLORREF ColorSet(UINT, COLORREF);
  216.         virtual COLORREF ColorGet(UINT);
  217.  
  218.         virtual UINT     LineStyleSet(UINT);
  219.         virtual UINT     LineStyleGet();
  220.     };
  221.  
  222. typedef CSchmooDoc FAR * LPCSchmooDoc;
  223.  
  224.  
  225. //These color indices wrap the polyline definitions
  226. #define DOCCOLOR_BACKGROUND             POLYLINECOLOR_BACKGROUND
  227. #define DOCCOLOR_LINE                   POLYLINECOLOR_LINE
  228.  
  229.  
  230.  
  231. #endif //_COSCHMOO_H_
  232.